home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3369 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.0 KB

  1. Path: news.kei.com!ub!newserve!rebecca!rpi!not-for-mail
  2. From: floydb1@lib104.its.rpi.edu (Barry B Floyd)
  3. Newsgroups: comp.lang.c++,comp.lang.c
  4. Subject: Re: getch() equivalency help ...
  5. Date: 23 Jan 1996 09:41:24 -0500
  6. Organization: Rensselaer Polytechnic Institute, Troy, NY.
  7. Message-ID: <4e2s2k$6qj@lib104.its.rpi.edu>
  8. References: <4dpe6p$e4j@twin.wasatch.com> <4e11eh$l96@hacgate2.hac.com>
  9. NNTP-Posting-Host: lib104.its.rpi.edu
  10. X-newsreader: xrn 7.04-beta-11
  11.  
  12.  
  13. In article <4e11eh$l96@hacgate2.hac.com>, collins@thor.tu.hac.com (Ron Collins) writes:
  14. |> Richard Demanowski (rdemanow@wasatch.com) wrote:
  15. |> : I am looking for help with the following question/problem:
  16. |> 
  17. |> : I want to have a function that does the same thing as getch() from
  18. |> : conio.h, but without needing to include conio.h.
  19. |>  [snip]
  20. |> 
  21. |> There is no portable way to do this.  There are portable ways to read an
  22. |> entire line [fgets(stdin)], but if you need just one character, then
  23. |> you'll have to write OS specific code for each machine type.
  24. |> 
  25. |> Probably the easiest thing to do would be to put curses on all machines
  26. |> (it exists for almost any OS you can think of, and can generally be found
  27. |> for free).
  28. |> 
  29. |>             -- Collins --
  30.  
  31.  
  32. I was battling with this problem as well, using iostreams. Apparently
  33. there isn't any way to do this with ">>", get( char *, LEN, DELIM ),
  34. read ( POINTER, LEN ), int get (), get ( char& C ).
  35.  
  36. I was hopefull with the last two ( i.e. get a single character and
  37. put it in int/char& C. But everything is buffered.
  38.  
  39. Is there a way to do this with the underlying/base class 'buf'?
  40.  
  41. A related problem: after (temporarily) resigning myself to pressing
  42. the ENTER key after typing a character, I started playing with the
  43. ignore ( LEN, DELIM ) function. I want to ignore what ever "may"
  44. have been typed after the first character. Sometimes the buffer will
  45. be empty, sometimes not. I tried testing for EOF, and other 'fail'ures.
  46. I got expected results when inputting to a 'char' but had difficulties
  47. with 'char *'. The EOF flag seems to be set upon conditions I don't
  48. understand.
  49.  
  50.  
  51. Are there any code samples for using 'cin' functions? I have 
  52. checked the FAQ and the usual WEB pages, but have found nothing
  53. to helpful. The most help has come from:
  54.  
  55.    GNU's g++/.../src/libio/iostream.info-1
  56.  
  57. on our UNIX system.
  58.  
  59. Ultimately, what I would like to have ( and have done in other
  60. languages ) is the following:
  61.  
  62.    int GetOption ( void ) 
  63.    {
  64.       String valid_chars = "somecharacters" ;
  65.       int char_num = valid_chars.index ( cin.ASCII_or_scan_code () ) ;
  66.  
  67.       while (  char_num == -1 ) 
  68.          valid_chars.index ( cin.ASCII_or_scan_code () ) ;
  69.  
  70.       switch char_num
  71.       {
  72.           case ...
  73.       }
  74.    
  75.       return ( char_num ) ;
  76.    }
  77.  
  78.  
  79. thanks
  80.  
  81. barry      
  82. -- 
  83. +--------------------------------------------------------------------+ 
  84. | Barry B. Floyd                   \\\               floydb1@rpi.edu |
  85. | RPI Alum. '84 '87 '88              \\\                             |
  86. +--------------------------------------------------------------------+
  87.